/*
 * @lc app=leetcode.cn id=383 lang=javascript
 *
 * [383] 赎金信
 */

// @lc code=start
/**
 * @param {string} ransomNote
 * @param {string} magazine
 * @return {boolean}
 */
var canConstruct = function(ransomNote, magazine) {
    let magazineArr = magazine.split('')
    for (let index = 0; index < magazineArr.length; ) {
        const e = magazineArr[index];
        let indexFind = ransomNote.indexOf(e)
        if (indexFind === -1) {
            index++
        } else {
            ransomNote = ransomNote.substring(0, indexFind) + ransomNote.substring(indexFind + 1)
            magazineArr.splice(index, 1)
        }
    }
    if (ransomNote.length === 0) {
        return true
    }
    return false
};
// @lc code=end

